<!--
 * @Author: 高瑞寒 15932717091@163.com
 * @Date: 2021-07-10 11:27:37
 * @LastEditTime: 2022-05-31 14:53:03
 * @LastEditors: 高瑞寒 15932717091@163.com
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id='app'>123</div>
</body>
<script>
  let data = {
    a: 'a',
    b: 'b'
  }
  let vm = {}
  Object.keys(data).forEach(item => {
    defineReactive(vm, item, data[item])
  })
  function defineReactive(obj, key, val) {
    Object.defineProperty(obj, key, {
      get() {
        console.log('访问');
        return val
      },
      set(newVal) {
        console.log('设置');
        val = newVal
        document.querySelector('#app').innerHTML = val
      }
    })
  }
</script>

</html>